From 442de299aec208b58f3c004040927e62c63788c7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 14 Nov 2014 08:49:01 -0800 Subject: [PATCH] Polish off the LTO branch --- Cargo.lock | 14 ++++++++++++-- Cargo.toml | 3 +++ src/cargo/core/manifest.rs | 3 --- src/cargo/ops/cargo_rustc/mod.rs | 7 +++---- src/doc/manifest.md | 7 ++++++- tests/test_cargo_compile.rs | 16 +++++++++------- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b48ba2225..8db34ac77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,7 @@ dependencies = [ "registry 0.0.1-pre", "semver 0.1.0 (git+https://github.com/rust-lang/semver)", "tar 0.0.1 (git+https://github.com/alexcrichton/tar-rs)", + "time 0.0.1 (git+https://github.com/rust-lang/time)", "toml 0.1.0 (git+https://github.com/alexcrichton/toml-rs)", "url 0.1.0 (git+https://github.com/servo/rust-url)", ] @@ -92,9 +93,10 @@ source = "git+https://github.com/alexcrichton/gcc-rs#f23b4ba15348508b9ac557fc7ee [[package]] name = "git2" version = "0.0.1" -source = "git+https://github.com/alexcrichton/git2-rs#847a4902f3e0971c394ac3f35995e49a774b275a" +source = "git+https://github.com/alexcrichton/git2-rs#afec995029fae2d1eedf4d635b2131080b5b196d" dependencies = [ "libgit2-sys 0.0.1 (git+https://github.com/alexcrichton/git2-rs)", + "time 0.0.1 (git+https://github.com/rust-lang/time)", "url 0.1.0 (git+https://github.com/servo/rust-url)", ] @@ -111,7 +113,7 @@ source = "git+https://github.com/carllerche/hamcrest-rust.git#998036d000095f72c8 [[package]] name = "libgit2-sys" version = "0.0.1" -source = "git+https://github.com/alexcrichton/git2-rs#847a4902f3e0971c394ac3f35995e49a774b275a" +source = "git+https://github.com/alexcrichton/git2-rs#afec995029fae2d1eedf4d635b2131080b5b196d" dependencies = [ "libssh2-sys 0.0.1 (git+https://github.com/alexcrichton/ssh2-rs)", "openssl-sys 0.0.1 (git+https://github.com/alexcrichton/openssl-sys)", @@ -174,6 +176,14 @@ name = "tar" version = "0.0.1" source = "git+https://github.com/alexcrichton/tar-rs#47d2cc4b09e373a4cc7bee7c71ebf96b42ea620d" +[[package]] +name = "time" +version = "0.0.1" +source = "git+https://github.com/rust-lang/time#76698f52381a78cf654dbedfefd04c28a9806788" +dependencies = [ + "gcc 0.0.1 (git+https://github.com/alexcrichton/gcc-rs)", +] + [[package]] name = "toml" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index b3f3f7a98..f36405f84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,9 @@ git = "https://github.com/alexcrichton/git2-rs" [dependencies.glob] git = "https://github.com/rust-lang/glob" +[dependencies.time] +git = "https://github.com/rust-lang/time" + [dependencies.registry] path = "src/registry" diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 0e96a8d7b..aa220227c 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -162,7 +162,6 @@ impl Profile { Profile { env: "compile".to_string(), // run in the default environment only opt_level: 0, - lto: false, debug: true, .. Profile::default() } @@ -182,7 +181,6 @@ impl Profile { Profile { env: "bench".to_string(), opt_level: 3, - lto: false, test: true, dest: Some("release".to_string()), .. Profile::default() @@ -193,7 +191,6 @@ impl Profile { Profile { env: "release".to_string(), opt_level: 3, - lto: false, dest: Some("release".to_string()), .. Profile::default() } diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index ebecb321a..f9168c065 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -579,12 +579,11 @@ fn build_base_args(cx: &Context, if profile.get_opt_level() != 0 { cmd = cmd.arg("--opt-level").arg(profile.get_opt_level().to_string()); } - if target.is_bin() && profile.get_lto() { + if (target.is_bin() || target.is_staticlib()) && profile.get_lto() { cmd = cmd.args(["-C", "lto"]); } else { - // @alexchrichton says that there may be some restrictions with LTO - // and codegen-units, so that we should only add codegen units when - // LTO is not used. + // There are some restrictions with LTO and codegen-units, so we + // only add codegen units when LTO is not used. match profile.get_codegen_units() { Some(n) => cmd = cmd.arg("-C").arg(format!("codegen-units={}", n)), None => {}, diff --git a/src/doc/manifest.md b/src/doc/manifest.md index 757183370..41aaeb4f8 100644 --- a/src/doc/manifest.md +++ b/src/doc/manifest.md @@ -142,30 +142,35 @@ along with the defaults for each profile. opt-level = 0 # Controls the --opt-level the compiler builds with debug = true # Controls whether the compiler passes -g or `--cfg ndebug` rpath = false # Controls whether the compiler passes `-C rpath` +lto = false # Controls `-C lto` for binaries and staticlibs # The release profile, used for `cargo build --release` [profile.release] opt-level = 3 debug = false rpath = false +lto = false # The testing profile, used for `cargo test` [profile.test] opt-level = 0 debug = true rpath = false +lto = false # The benchmarking profile, used for `cargo bench` [profile.bench] opt-level = 3 debug = false rpath = false +lto = false # The documentation profile, used for `cargo doc` [profile.doc] opt-level = 0 debug = true rpath = false +lto = false ``` # The `[features]` Section @@ -187,7 +192,7 @@ name = "awesome" # The "default" set of optional packages. Most people will # want to use these packages, but they are strictly optional -default = ["jquery", "uglifier"] +default = ["jquery", "uglifier", "session"] # The "secure-password" feature depends on the bcrypt package. # This aliasing will allow people to talk about the feature in diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 43c696a98..64af6f2c9 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -740,20 +740,22 @@ test!(lto_build { name = "test" version = "0.0.0" authors = [] + + [profile.release] lto = true "#) .file("src/main.rs", "fn main() {}"); - assert_that(p.cargo_process("build").arg("-v"), + assert_that(p.cargo_process("build").arg("-v").arg("--release"), execs().with_status(0).with_stdout(format!("\ {compiling} test v0.0.0 ({url}) -{running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type bin -g \ +{running} `rustc {dir}{sep}src{sep}main.rs --crate-name test --crate-type bin \ + --opt-level 3 \ -C lto \ - -C metadata=[..] \ - -C extra-filename=-[..] \ - --out-dir {dir}{sep}target \ + --cfg ndebug \ + --out-dir {dir}{sep}target{sep}release \ --dep-info [..] \ - -L {dir}{sep}target \ - -L {dir}{sep}target{sep}deps` + -L {dir}{sep}target{sep}release \ + -L {dir}{sep}target{sep}release{sep}deps` ", running = RUNNING, compiling = COMPILING, sep = path::SEP, dir = p.root().display(), -- 2.30.2